const BinaryTree = require("../utils/binaryTree")
let arr = [5,4,8,11,null,13,4,7,2,null,null,5,1]
let rootObj = new BinaryTree(arr);

var pathSum = function(root, target) {
    let result = []
    function dfs(node,currentPath,currentSum){
        if(!node)return
        currentPath.push(node.val)
        currentSum+=node.val
        if(!node.left && !node.right && currentSum===target){
            result.push([...currentPath])
        }
        dfs(node.left,currentPath,currentSum)
        dfs(node.right,currentPath,currentSum)
        currentPath.pop()
    }
    dfs(root,[],0)
    return result
};

const result = pathSum(rootObj.root,22)
console.log("🚀 ~ result:", result)
